mydata <- get_ecodata("https://fred.stlouisfed.org/series/MORTGAGE30US")
ggplot_ecodata_ts(mydata, title = "Mortgage Interest Rate - Fixed Rate 30-Year", plot.recessions = TRUE)
Department of Economics
University of Wisconsin-La Crosse
Email: jmurray@uwlax.edu
St. Louis Fed Professors’ Conference
November 8, 2024
Want to start using the ECODATA R package right now?
Live RStudio project on Posit Cloud!
Login / Create Posit Cloud account at https://posit.cloud
Create your own copy of the ECODATA Exercises project by following:
Login / Create FRED account at https://fred.stlouisfed.org/
(click My Account at top left)
Get your FRED key at https://fredaccount.stlouisfed.org/apikeys
Copy that 32-character key and in the Posit Cloud console, set the key:
ecodata::ecodata_set_fredkey("abcd1234efgh5678ijkl9012mnop3456")
Learn more at https://murraylax.org/ecodata/
Student explored data on both FRED and World Bank Data
Student picked relevant variables, explained it correctly
Cogent international comparisons of the great recession
Great interactive tools made for poor visualizations (at least default values)
Time consuming to reproduce - Return to website, download image, etc.
Inconsistent style across FRED and World Bank Data
Very difficult to see much of the text
Created an R package, ecodata, to facilitate visualizing data in undergraduate macroeconomics courses
Wrapper for the fredr, wbstats, and ggplot2 packages
Makes it easy to:
Download data from the Federal Reserve Economic Data (FRED) and World Bank databases
Produce professional-quality data visualizations
View descriptions of the data
Cite sources
Do everything with 3-4 lines of code
Not a substitute for fredr, wbstats, or ggplot2, nor for exploring data and using interactive tools in FRED and World Bank Data
mydata <- get_ecodata("https://fred.stlouisfed.org/series/MORTGAGE30US")
ggplot_ecodata_ts(mydata, title = "Mortgage Interest Rate - Fixed Rate 30-Year", plot.recessions = TRUE)# Identify what variables I want
# Includes both FRED and World Bank Data sources
variable_sources <- c(
"https://fred.stlouisfed.org/series/UNRATE",
"https://fred.stlouisfed.org/series/AURUKM",
"https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG?locations=US",
"https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG?locations=GB"
)
# Optionally, provide my own names for the variables
variable_names <- c(
"Unemployment Rate: United States",
"Unemployment Rate: United Kingdom",
"Inflation Rate: United States",
"Inflation Rate: United Kingdom"
)
# Fetch the data
mydata <- get_ecodata(variable_sources, variable_names)
# Get only Great Recession + Recovery
mydata <- mydata |>
filter(Date >= "2007-01-01" & Date <= "2016-12-31")ggplot_ecodata_facet(mydata,
ncol = 2,
title = "Unemployment and Inflation in U.S. and U.K.",
plot.recession = TRUE)Variable | Code | Description | Frequency | Units | Seasonal Adjustment | Source | URL | Access Date |
|---|---|---|---|---|---|---|---|---|
Unemployment Rate: United States | UNRATE | Unemployment Rate | Monthly | % | Seasonally Adjusted | FRED (R) Federal Reserve Bank of St. Louis | October 30, 2024 | |
Unemployment Rate: United Kingdom | AURUKM | Unemployment Rate in the United Kingdom | Monthly | % | Seasonally Adjusted | FRED (R) Federal Reserve Bank of St. Louis | October 30, 2024 | |
Inflation Rate: United States | FP.CPI.TOTL.ZG?locations=US | Inflation as measured by the consumer price index reflects the annual percentage change in the cost to the average consumer of acquiring a basket of goods and services that may be fixed or changed at specified intervals, such as yearly. The Laspeyres formula is generally used. | Annual | Index | Not Seasonally Adjusted | World Bank Data | https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG?locations=US | October 30, 2024 |
Inflation Rate: United Kingdom | FP.CPI.TOTL.ZG?locations=GB | Inflation as measured by the consumer price index reflects the annual percentage change in the cost to the average consumer of acquiring a basket of goods and services that may be fixed or changed at specified intervals, such as yearly. The Laspeyres formula is generally used. | Annual | Index | Not Seasonally Adjusted | World Bank Data | https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG?locations=GB | October 30, 2024 |
All the documentation: https://murraylax.org/ecodata/
Walks through many of the most common uses of the package.
Download data for multiple states or countries with ease
Plots with multiple variables, bar plots
Data transformations, computing new quantities
Instructional Vignettes
Reproducible: The code is the set of instructions for what you created
Efficient: Difficult to make the first graph, but it’s easy to make the 2nd and 100th graphs!
Flexible: Can easily change the data, the graph, the labels, etc.
Used in other courses: R is used in econometrics, statistics, data science, etc.
Used in industry, even among those who are not data scientists
Even more important / relevant with AI
AI assistance makes coding more accessible
Verification and reproducibility is key with AI-generated content
Steep learning curve
Easy to do the hard things, but hard to do the easy things
This is Principles of Macroeconomics, not what I signed up for!
ECODATA Package
Gentle learning curve!
Easy to do easy things
Use simple reproducible code to analyze macroeconomics principles
Data visualization is a key skill for everyone
Early introduction makes subsequent classes easier
Data is used throughout the economics discipline, it should be used throughout economics curriculum
Repeated practice throughout undergraduate degree builds mastery
Data on construction prices, new house prices, and housing starts.
Does a supply and demand model prediction explain the data?
Exchange Rates and Interest Rates
Data on exchange rates and interest rates interest rates in U.K. and U.S.
Does a supply and demand model for currencies explain the data?
And I will be making a lot more!
Show students worked-out examples - See my vignettes!
Create prompts that require only 1-2 lines of code to answer the question
Make economics real: Compare theoretical predictions with recent data
Be mindful of opportunity costs - Do more data analysis means doing less of something else in the class
You have or envision a short low-stakes assignment where students visualize macroeconomic data?
Answer these questions about one such assignment:
What is the macroeconomics concept or theory that students apply?
What variables do the students need?
What will the students discover?
Share your ideas! Email: jmurray@uwlax.edu
What me to create instructional vignette around your idea? Let me know!